<?php defined('BASEPATH') OR exit('No direct script access allowed');

if ( ! class_exists('Controller'))
{
	class Controller extends CI_Controller {}
}

class Building extends Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->library('ion_auth');
		$this->load->library('session');
		$this->load->library('form_validation');
		$this->load->database();
		$this->load->helper('url');
		$this->load->library('ion_auth');
		$this->currentuser=$this->ion_auth->user()->row();
		$this->data['username']=$this->currentuser->username;
	}

	function xibo(){
		
		$this->data['js'] = "";
		$this->data['css'] = "";
		$this->load->model('user_model');
		$this->load->model('building_model');
		$groupid=$this->user_model->getGroupId($this->currentuser->id);
		$buildingid=$this->building_model->getBuildingId($groupid);	
		$this->data['child']=$this->user_model->getChildId($groupid);
		$buildingname=$this->building_model->getValue('name','id='.$buildingid);
		$this->data['ip']=$this->building_model->getValue('ip','id='.$buildingid);
		$this->data['title'] = $buildingname."'s Xibo";
		$this->load->view('header_view',$this->data);
		$this->load->view('building/building_xibo',$this->data);
		$this->load->view('footer_view');
	}
	function addition(){
		$this->data['title'] = "Create User";
		$this->data['js'] = "";
		$this->data['css'] = "";
		$this->load->model('building_model');
		$this->data['buildingtypelist']=$this->building_model->get_building_type_list('select list');
		$this->data['building']=$this->building_model->getAll();
		$this->data['building_model']=$this->building_model;
		$this->load->view('header_view',$this->data);
		$this->load->view('building/building_addition',$this->data);
		$this->load->view('footer_view');
	}
	
	//create a new user
	function addition_action()
	{
		$this->load->model('building_model');
		$this->data['title'] = "Create Building";

		
		$data = array('name' => $this->input->post('name'),
				'city' => $this->input->post('city'),
				'building_type_id' => $this->input->post('building_type_id'),
				'ip' => $this->input->post('ip')
		);
		$this->building_model->insert($data);
		$response=1;	
		$message="pendaftaran berhasil";
			
		$data=array("message"=>$message);
		echo json_encode(array("response"=>$response,"data"=>$data));
	}

}
